﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Pretext.Logging {
	public class LogItem {

		public LogItem(LogItemType type, string message, Token relatedToken, string sourceFileDescription)
			: this(type, message, relatedToken) {
			SourceFileDescription = sourceFileDescription;
		}

		public LogItem(LogItemType type, string message, Token relatedToken) {
			this.Type = type;
			this.Message = message;
			RelatedToken = relatedToken;
			SourceFileDescription = relatedToken.SourceFileDescription;
		}

		public LogItemType Type { get; private set; }
		public string Message { get; private set; }
		public Token RelatedToken { get; private set; }
		public string SourceFileDescription { get; private set; }

		public string ToOutputString() {

			if (RelatedToken != null && Type == LogItemType.Error)
				return string.Format("{0}: {1} in \"{3}\" on line {2}.", this.Type, this.Message, RelatedToken.LineNumber, SourceFileDescription);
			else if (RelatedToken != null)
				return string.Format("{0}: ({2}) {1}", this.Type, this.Message, RelatedToken.LineNumber, SourceFileDescription);
			else
				return string.Format("{0}: {1}", this.Type, this.Message);
		}

	}
}